package rpcm

import (
	"fmt"
	"github.com/chenwbyx/leafserver/server/models"
)

type BackPack struct {
	ID         int `gorm:"primary_key;AUTO_INCREMENT"`
	UserId     int `gorm:"not null;unique"`
	PropID     int `gorm:"not null;unique"`
	PropCounts int `gorm:"not null;unique"`
	PropExpire int64
	models.Model
}

func getUserBackPackByUserId(userId int) *[]BackPack {
	var backPacks []BackPack
	// gorm的database
	if rs := models.Db.HasTable(&BackPack{}); !rs {
		models.Db.AutoMigrate(&BackPack{})
	}
	err := models.Db.Where("user_id = ?", userId).Find(&backPacks).Error
	if nil != err {
		fmt.Println(err)
		return nil
	}
	fmt.Println("backPack:", backPacks)
	return &backPacks
}
